// pages/examine/index.js
const db = wx.cloud.database()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		gooodsItem: [],
		zhezhao: true,
		chakan:Number,
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		db.collection("examine").get().then(res => {
			this.setData({
				gooodsItem: res.data
			})
		})
	},
	check(e) {
		console.log("查看");
		this.setData({
			chakan:e.currentTarget.dataset.index
		})
		this.setData({
			zhezhao: !this.data.zhezhao
		})
	},
	adopt(e) {
		// console.log("通过");
		// let index = e.currentTarget.dataset.index
		// let gooods = this.data.gooodsItem[index]
		// wx.cloud.callFunction({
		// 	name: "adopt",
		// 	data: {
		// 		gooodsItem: gooods
		// 	}
		// })
		// let all = this.data.gooodsItem
		// all.splice(index, 1)
		// this.setData({
		// 	gooodsItem: all
		// })

		wx.showModal({
			title: '提示',
			content: '确定通过吗？',
			success(res) {
				if (res.confirm) {
					let index = e.currentTarget.dataset.index
					let gooods = this.data.gooodsItem[index]
					wx.cloud.callFunction({
						name: "adopt",
						data: {
							gooodsItem: gooods
						}
					})
					let all = this.data.gooodsItem
					all.splice(index, 1)
					this.setData({
						gooodsItem: all
					})
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})
		

	},
	fail(e) {
		let index = e.currentTarget.dataset.index
		console.log("未通过");
		wx.showModal({
			title: '请输入违规问题',
			editable: true,
			success: res => {
				if (res.confirm) {
					console.log(res.content)
					let gooodsItem = this.data.gooodsItem[index]
					gooodsItem.Violation = res.content
					console.log(gooodsItem);
					wx.cloud.callFunction({
						name: "examine",
						data: {
							gooodsItem
						}
					})
					let all = this.data.gooodsItem
					all.splice(index, 1)
					this.setData({
						gooodsItem: all
					})
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})
	},
	off() {
		this.setData({
			zhezhao: !this.data.zhezhao
		})
	},


	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})